<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('合伙企业列表') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true" @submit.native.prevent>
      <el-form-item :label="$t('合伙企业名称')" prop="name">
        <el-input
          v-model="queryParams.name"
          :placeholder="$t('合伙企业名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="hhqyBaseList" border>
      <el-table-column :label="$t('序号')" fixed type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('合伙企业名称')" fixed align="center" prop="name" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/hhqy/base/hhqyBaseHome',query:{id:scope.row.id}}"
            class="link_a"
          >{{ scope.row.name }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('执行事务合伙人')" align="center" prop="executivePartner" show-overflow-tooltip width="120" />
      <el-table-column :label="$t('执行事务合伙人委派代表')" align="center" prop="appoints" width="200" />
      <el-table-column :label="$t('成立时间')" align="center" prop="established" show-overflow-tooltip width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.established) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('企业统一社会信用代码')" align="center" prop="creditCode" show-overflow-tooltip width="140" />
      <el-table-column :label="$t('执照登记日期')" align="center" prop="registerDate" show-overflow-tooltip width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.registerDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('合伙期限')" align="center" prop="partnershipTerm" show-overflow-tooltip width="100" />
      <el-table-column :label="$t('基本户')" align="center" prop="baseAccount" show-overflow-tooltip width="90" />
      <el-table-column :label="$t('经营场所')" align="center" prop="businessPlace" show-overflow-tooltip />
      <el-table-column :label="$t('经营范围')" align="center" prop="businessRange" show-overflow-tooltip />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改合伙公司基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <hhqyBaseForm ref="hhqyBaseForm" />
    </el-dialog>
  </div>
</template>

<script>
import { getListByActStatus, delHhqyBase, exportHhqyBase } from '@/api/hhqy/base/hhqyBase'
import hhqyBaseForm from './hhqyBaseForm.vue'
export default {
    components: {
        hhqyBaseForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 合伙公司基本信息表格数据
          hhqyBaseList: [],
          // 弹出层标题
          title: '',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              name: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
  },
  methods: {
    /** 查询合伙公司基本信息列表 */
    getList() {
        this.loading = true
        getListByActStatus(this.queryParams).then(response => {
            this.hhqyBaseList = response.rows
            this.total = response.total
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            name: undefined,
            executivePartner: undefined,
            appoints: undefined,
            established: undefined,
            creditCode: undefined,
            registerDate: undefined,
            partnershipTerm: undefined,
            baseAccount: undefined,
            businessPlace: undefined,
            businessRange: undefined,
            delFlag: undefined,
            createBy: undefined,
            updateBy: undefined,
            createTime: undefined,
            updateTime: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.title = this.$t('合伙企业基本信息')
        this.$nextTick(() => {
            this.$refs.hhqyBaseForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.title = this.$t('合伙企业基本信息')
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.hhqyBaseForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delHhqyBase(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return exportHhqyBase(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(function() {
        })
    }
  }
}
</script>
